public without sharing class RightsConfirmationController {

	public String msg {get;private set;}
    public Boolean isErr {get;private set;}
	public Boolean isSuccess {get; private set;}

	public String dataJson {get;private set;}
	public String saveJson {get;set;}
    public String backId {get;private set; }
    public RightsConfirmation__c rc {get; private set;}
    public String combobox {get; private set;}
    public Boolean isAssist {get; private set;}
    public RightsConfirmationController() {
        backId = System.currentPageReference().getParameters().get('id');
    }

     public Boolean rightsContains(User u ){
        List<String> rights = Label.PerformanceImportRight.split(',',-1);
        for(String right : rights){
            if(right == u.Name || right == u.Profile.Name )return true;
        }
        return false;
    }
    public void init(){
        try {
            
            rc = [select Id ,Province__c,Company__c, Quarter__c, Year__c ,Status__c from RightsConfirmation__c where Id =:backId];

             User u = [select Profile.Name ,Name from User where Id=:UserInfo.getUserId()];

            isAssist = u.Profile.Name == '系统管理员' ||  rightsContains(u);
             getDetails();
             if(System.currentPageReference().getParameters().get('export') != null )return;
            if(rc.Status__c == '审批成功' || rc.Status__c  == '审批中') throw new DmlException(rc.Status__c + '不能修改');

           
            combobox = JSON.serialize(ImportObject.getPicklistValues('RightsConfirmationList__c', 'Company__c', true)) ;


        }
        catch (Exception e) {
            isErr = true ;
            ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR ,e.getMessage()));
        }
        
        
    }

    private void getDetails(){
    	List<DetailBean> tmp = new List<DetailBean>();
    	for(RightsConfirmationList__c rcl : 
    		[select Id,RightsConfirmation__c,AccountName__c,Company__c,Account__r.DirectSale__c ,TerminalAccount__r.Level__c,
    		Province__c,TerminalAccountName__c,AccountPK__c,TerminalPK__c, 
            
            DirectBusinessOwner__c,DirectBusinessOwner__r.Name,DirectBusinessOwner__r.ExuserCode__c,
    		DirectBusinessOwnerManager__c,DirectBusinessOwnerManager__r.Name,DirectBusinessOwnerManager__r.ExuserCode__c,
            
            DistributionOwner__c,DistributionOwner__r.Name,DistributionOwner__r.ExuserCode__c,
    		DistributionOwnerManager__c,DistributionOwnerManager__r.Name,DistributionOwnerManager__r.ExuserCode__c,
            
            ProvinceManager__c,ProvinceManager__r.Name ,ProvinceManager__r.ExuserCode__c,

            TripartiteOwner__c,TripartiteOwner__r.Name,TripartiteOwner__r.ExuserCode__c,
    		TripartiteOwnerManager__c,TripartiteOwnerManager__r.Name,TripartiteOwnerManager__r.ExuserCode__c ,

            BiochemicalIOwnerManager__c,BiochemicalIOwnerManager__r.Name ,BiochemicalIOwnerManager__r.ExuserCode__c,
            BiochemicalIOwner__c,BiochemicalIOwner__r.Name ,BiochemicalIOwner__r.ExuserCode__c,

            PathologyOwnerManager__c,PathologyOwnerManager__r.Name,PathologyOwnerManager__r.ExuserCode__c,
            PathologyOwner__c,PathologyOwner__r.Name ,PathologyOwner__r.ExuserCode__c,

            POCTOwnerManager__c,POCTOwnerManager__r.Name,POCTOwnerManager__r.ExuserCode__c,
            POCTOwner__c,POCTOwner__r.Name,POCTOwner__r.ExuserCode__c,

            ImmunityOwnerManager__c,ImmunityOwnerManager__r.Name,ImmunityOwnerManager__r.ExuserCode__c,
            ImmunityOwner__c,ImmunityOwner__r.Name ,ImmunityOwner__r.ExuserCode__c,
            
            SysmexOwner__c,SysmexOwner__r.Name, SysmexOwner__r.ExuserCode__c,
            SysmexOwnerManager__c,SysmexOwnerManager__r.Name, SysmexOwnerManager__r.ExuserCode__c,

            MolecularOwner__c,MolecularOwner__r.Name,MolecularOwner__r.ExuserCode__c,
            MolecularOwnerManager__c,MolecularOwnerManager__r.Name,MolecularOwnerManager__r.ExuserCode__c,

            MicrobeOwner__c,MicrobeOwner__r.Name, MicrobeOwner__r.ExuserCode__c,
            MicrobeOwnerManager__c,MicrobeOwnerManager__r.Name, MicrobeOwnerManager__r.ExuserCode__c,

            ClinicalLaboratoryOwner__c,ClinicalLaboratoryOwner__r.Name ,ClinicalLaboratoryOwner__r.ExuserCode__c,
            ClinicalLaboratoryOwnerManager__c,ClinicalLaboratoryOwnerManager__r.Name ,ClinicalLaboratoryOwnerManager__r.ExuserCode__c, 

            BDOwnerManager__c,BDOwnerManager__r.Name,BDOwnerManager__r.ExuserCode__c,
            BDOwner__c,BDOwner__r.Name ,BDOwner__r.ExuserCode__c

    		from RightsConfirmationList__c where RightsConfirmation__c =:backId  ]){

    		tmp.add(new DetailBean(rcl));
    	}
    	dataJson = EncodingUtil.urlEncode(JSON.serialize(tmp), 'UTF-8');
    }
    public void setNil(){
    	dataJson = '[]';
    }

    @RemoteAction
    public static  Map<String,UserBean> matchUser(List<String> users ){

    	Map<String,UserBean> tmp =new Map<String,UserBean>();
    	for(User u:[select Id,Name , ExuserCode__c from User where ExuserCode__c in: users   ]){
    		tmp.put(u.ExuserCode__c, new UserBean(u));
    	}
        //and IsActive = true
    	return tmp;
    }

    public static String getUser(Object key ,Map<String,UserBean> uMap){

        if(key == null)return null;
        if(String.isBlank((String)key))return null;
        return uMap.containsKey((String) key) ? uMap.get((String) key).id : null  ;


    }
    @RemoteAction
    public static String  importData(String datas, List<String>users ,String year,String quarter ){

        Map<String,Object> resultMap = new Map<String,Object>();
        List<Object>errList = new List<Object>();
        
        List<Object> saveList = (List<Object> )JSON.deserializeUntyped(EncodingUtil.urlDecode(datas, 'UTF-8'));

        List<RightsConfirmationList__c> details = new List<RightsConfirmationList__c>();

        Map<String,Id> accMap = new Map<String,Id>();
        Map<String,UserBean> uMap  = matchUser(users);
        System.debug('importData=>'+users);
        System.debug('importData=>'+uMap);

        Set<String> exsets = new Set<String>();
        Set<String> exKeys = new Set<String>();

        Set<String> companys = new Set<String>();
        Set<String> provinces = new Set<String>();
        Set<String> accpks  = new Set<String>();
        Set<String> termpks  = new Set<String>();

        Boolean isNew = false;
        for (Object o  : saveList) {
           
           Map<String,Object> mo = (Map<String,Object>) o;

            RightsConfirmationList__c rcl = new RightsConfirmationList__c();
            rcl.Quarter__c = quarter ;
            rcl.Year__c = year ;
            rcl.Company__c = DataUtil.getStringValue(mo.get('company'));
            rcl.Province__c = DataUtil.getStringValue(mo.get('province'));


            
            rcl.Id = DataUtil.getStringValue(mo.get('detailId'));
            if(exsets.contains(rcl.Id ))continue;
            if(rcl.Id  != null )exsets.add(rcl.Id);
            if(rcl.Id == null )isNew = true;
           
            String accpk  = DataUtil.getStringValue(mo.get('accpk'));
            String terminalpk  = DataUtil.getStringValue(mo.get('terminalpk'));
            String key = rcl.Quarter__c + rcl.Year__c +rcl.Province__c+rcl.Company__c +accpk+terminalpk;

            if(exKeys.contains(key))continue;
            exKeys.add(key);

            companys.add(rcl.Company__c);
            provinces.add(rcl.Province__c);
            accpks.add(accpk);
            termpks.add(terminalpk);


            if(String.isNotBlank(accpk))rcl.AccountPK__c = accpk;//DataUtil.getStringValue(mo.get('accpk'));
            if(String.isNotBlank(terminalpk))rcl.TerminalPK__c = terminalpk;//DataUtil.getStringValue(mo.get('terminalpk'));
            rcl.AccountName__c = DataUtil.getStringValue(mo.get('accName'));
            rcl.TerminalAccountName__c = DataUtil.getStringValue(mo.get('terminalName'));

            rcl.ProvinceManager__c = getUser(mo.get('provinceno'),uMap);// DataUtil.getStringValue(mo.get('provinceId'));

            rcl.DistributionOwner__c = getUser(mo.get('caterno'),uMap);// DataUtil.getStringValue(mo.get('caterId'));
            rcl.DistributionOwnerManager__c = getUser(mo.get('caterMno'),uMap);//DataUtil.getStringValue(mo.get('caterManagerId'));

            rcl.DirectBusinessOwner__c =getUser(mo.get('salerno'),uMap);// DataUtil.getStringValue(mo.get('salerId'));
            rcl.DirectBusinessOwnerManager__c = getUser(mo.get('salerMno'),uMap);//DataUtil.getStringValue(mo.get('salerManagerId'));

            rcl.TripartiteOwner__c = getUser(mo.get('thirdno'),uMap);//DataUtil.getStringValue(mo.get('thirdId'));
            rcl.TripartiteOwnerManager__c = getUser(mo.get('thirdMno'),uMap);//DataUtil.getStringValue(mo.get('thirdManagerId'));

            rcl.BiochemicalIOwner__c =getUser(mo.get('shno'),uMap);// DataUtil.getStringValue(mo.get('shId'));
            rcl.BiochemicalIOwnerManager__c = getUser(mo.get('shManagerno'),uMap);//DataUtil.getStringValue(mo.get('shManagerId'));

             rcl.ImmunityOwner__c =getUser(mo.get('myno'),uMap);// DataUtil.getStringValue(mo.get('myId'));
            rcl.ImmunityOwnerManager__c = getUser(mo.get('myManagerno'),uMap);//DataUtil.getStringValue(mo.get('myManagerId'));

             rcl.ClinicalLaboratoryOwner__c =getUser(mo.get('ljno'),uMap);// DataUtil.getStringValue(mo.get('ljId'));
            rcl.ClinicalLaboratoryOwnerManager__c = getUser(mo.get('ljManagerno'),uMap);//DataUtil.getStringValue(mo.get('ljManagerId'));

            rcl.PathologyOwner__c = getUser(mo.get('blno'),uMap);//DataUtil.getStringValue(mo.get('blId'));
            rcl.PathologyOwnerManager__c =getUser(mo.get('blManagerno'),uMap);// DataUtil.getStringValue(mo.get('blManagerId'));

            rcl.POCTOwner__c = getUser(mo.get('poctno'),uMap);//DataUtil.getStringValue(mo.get('poctId'));
            rcl.POCTOwnerManager__c = getUser(mo.get('poctManagerno'),uMap);//DataUtil.getStringValue(mo.get('poctManagerId'));

            rcl.SysmexOwner__c =getUser(mo.get('xsmkno'),uMap);// DataUtil.getStringValue(mo.get('xsmkId'));
            rcl.SysmexOwnerManager__c =getUser(mo.get('xsmkManagerno'),uMap);// DataUtil.getStringValue(mo.get('xsmkManagerId'));

            rcl.MicrobeOwner__c = getUser(mo.get('wswno'),uMap);//DataUtil.getStringValue(mo.get('wswId'));
            rcl.MicrobeOwnerManager__c = getUser(mo.get('wswManagerno'),uMap);//DataUtil.getStringValue(mo.get('wswManagerId'));

            rcl.BDOwnerManager__c =  getUser(mo.get('bdManagerno'),uMap);//DataUtil.getStringValue(mo.get('bdManagerId'));
            rcl.BDOwner__c = getUser(mo.get('bdno'),uMap);// DataUtil.getStringValue(mo.get('bdId'));

            rcl.MolecularOwnerManager__c =getUser(mo.get('fzManagerno'),uMap);// DataUtil.getStringValue(mo.get('fzManagerId'));
            rcl.MolecularOwner__c = getUser(mo.get('fzno'),uMap);// DataUtil.getStringValue(mo.get('fzId'));
          
            details.add(rcl);


        }

        Integer cnt  = [select count() from RightsConfirmationList__c where Year__c =:year 
        and Quarter__c=:quarter and Company__c in:companys  and  Province__c in:provinces 
        and AccountPK__c in:accpks and TerminalPK__c in:termpks ];


        if(cnt > 0 && isNew){


            for(Object m : saveList){
                Map<String,Object> mo = (Map<String,Object>)m;
                mo.put('msg', '数据已存在');
                errList.add(mo);


            }


        }


        System.debug(details);

        SavePoint sp = Database.setSavepoint();
        try {

           
           if(!details.isEmpty()) upsert  details;
          
        }catch (Exception e) {
            Database.rollback(sp);
            for(Object m : saveList){
                Map<String,Object> mo = (Map<String,Object>)m;
                mo.put('msg', '保存失败!'+e.getMessage() + '  '+ e.getStackTraceString());
                errList.add(mo);
            }
        }
        resultMap.put('errData', errList);

        return EncodingUtil.urlEncode(JSON.serialize(resultMap), 'UTF-8') ;



    }

    public void save(){
    	msg = '';
    	try {
    		List<Object> saveList = (List<Object>)JSON.deserializeUntyped(EncodingUtil.urlDecode(saveJson, 'UTF-8'));

    		List<RightsConfirmationList__c> details = new List<RightsConfirmationList__c>();
    		for(Object o :saveList){
    			Map<String,Object> mo = (Map<String,Object>)o;
    			RightsConfirmationList__c rcl = new RightsConfirmationList__c();
    			rcl.Id = DataUtil.getStringValue(mo.get('detailId'));
    			if(String.isBlank(rcl.Id)){
    				msg = '数据Id为空,异常数据!';
    				return;
    			}
                rcl.ProvinceManager__c =  DataUtil.getIdValue(mo.get('provinceId'));

    			rcl.DistributionOwner__c =  DataUtil.getIdValue(mo.get('caterId'));
    			rcl.DistributionOwnerManager__c = DataUtil.getIdValue(mo.get('caterManagerId'));

    			rcl.DirectBusinessOwner__c = DataUtil.getIdValue(mo.get('salerId'));
    			rcl.DirectBusinessOwnerManager__c = DataUtil.getIdValue(mo.get('salerManagerId'));

    			// rcl.TripartiteOwner__c = DataUtil.getIdValue(mo.get('thirdId'));
    			// rcl.TripartiteOwnerManager__c = DataUtil.getIdValue(mo.get('thirdManagerId'));

                rcl.BiochemicalIOwner__c = DataUtil.getIdValue(mo.get('shId'));
                rcl.BiochemicalIOwnerManager__c = DataUtil.getIdValue(mo.get('shManagerId'));

                 rcl.ImmunityOwner__c = DataUtil.getIdValue(mo.get('myId'));
                rcl.ImmunityOwnerManager__c = DataUtil.getIdValue(mo.get('myManagerId'));

                 rcl.ClinicalLaboratoryOwner__c = DataUtil.getIdValue(mo.get('ljId'));
                rcl.ClinicalLaboratoryOwnerManager__c = DataUtil.getIdValue(mo.get('ljManagerId'));

                //  rcl.PathologyOwner__c = DataUtil.getIdValue(mo.get('blId'));
                // rcl.PathologyOwnerManager__c = DataUtil.getIdValue(mo.get('blManagerId'));

                // rcl.POCTOwner__c = DataUtil.getIdValue(mo.get('poctId'));
                // rcl.POCTOwnerManager__c = DataUtil.getIdValue(mo.get('poctManagerId'));

                rcl.SysmexOwner__c = DataUtil.getIdValue(mo.get('xsmkId'));

                rcl.SysmexOwnerManager__c = DataUtil.getIdValue(mo.get('xsmkManagerId'));

                rcl.MicrobeOwner__c = DataUtil.getIdValue(mo.get('wswId'));
                rcl.MicrobeOwnerManager__c = DataUtil.getIdValue(mo.get('wswManagerId'));

                rcl.BDOwnerManager__c =  DataUtil.getIdValue(mo.get('bdManagerId'));
                rcl.BDOwner__c =  DataUtil.getIdValue(mo.get('bdId'));

                // rcl.MolecularOwnerManager__c = DataUtil.getIdValue(mo.get('fzManagerId'));
                // rcl.MolecularOwner__c =  DataUtil.getIdValue(mo.get('fzId'));

                rcl.Quarter__c = rc.Quarter__c ;
                rcl.Year__c = rc.Year__c;
    			details.add(rcl);
    		}

    		SavePoint sp = Database.setSavepoint();
    		try {
    		    if(!details.isEmpty())update details;
    		    isSuccess = true;
    		    msg = '保存成功!';
    		}
    		catch (Exception e) {
    		     msg ='保存失败:'+ e.getMessage()+e.getStackTraceString() ;
    		}
    		
    	    
    	}

    	catch (Exception e) {
    	    msg ='保存失败:'+ e.getMessage() +e.getStackTraceString();
    	}

        System.debug('save=>'+msg);
    	

    }

    public class UserBean{
    	public String id;
    	public String name;
    	public String uno;
    	public UserBean(User u ){
    		id = u.Id;
    		name = u.Name;
    		uno = u.ExuserCode__c;
    	}
    }
    public class DetailBean{

    	public String mainId;
    	public String detailId;

    	public String accName ; //开票客户

        public String accpk; //客户 pk 
        public String terminalpk; // 终端 pk

    	public String terminalName ;//终端客户
    	public String company ;//归口公司

    	public String province;//归口省份

    	//public String cate ;//产品线/产品大类
    	public String accType ;//管理属性
    	public String terminalLevel ; //开票客户等级

    	public String salerId ;//直销人员Id ;
    	public String salerName ;
    	public String salerno;

    	public String salerManagerId;//直销管理从员
    	public String salerManagerName;
    	public String salerMno;

    	public String caterId ;//分销人员
    	public String caterName;
		public String caterno;

    	public String caterManagerId;//分销管理人员
    	public String caterManagerName;
    	public String caterMno;
        
        public String provinceId;//省区管理人员
        public String provinceName;
        public String provinceno;
        

    	public String thirdId;//三方人员
    	public String thirdName ; 
    	public String thirdno;

    	public String thirdManagerId;
    	public String thirdManagerName;
    	public String thirdMno;

        public String shId ;
        public String shName;
        public String shno;

        public String shManagerId;
        public String shManagerName;
        public String shManagerno;

        public String myId ;
        public String myName;
        public String myno;

        public String myManagerId;
        public String myManagerName;
        public String myManagerno;

        public String ljId ;
        public String ljName;
        public String ljno;

        public String ljManagerId;
        public String ljManagerName;
        public String ljManagerno;

        public String blId ;
        public String blName;
        public String blno;

        public String blManagerId;
        public String blManagerName;
        public String blManagerno;

        public String poctId ;
        public String poctName;
        public String poctno;

        public String poctManagerId;
        public String poctManagerName;
        public String poctManagerno;

        public String xsmkId ;
        public String xsmkName;
        public String xsmkno;

        public String xsmkManagerId;
        public String xsmkManagerName;
        public String xsmkManagerno;

        public String wswId ;
        public String wswName;
        public String wswno;

        public String wswManagerId;
        public String wswManagerName;
        public String wswManagerno;

        public String bdId ;
        public String bdName;
        public String bdno;

        public String bdManagerId;
        public String bdManagerName;
        public String bdManagerno;


        public String fzId ; 
        public String fzName;
        public String fzno ; 

        public String fzManagerId;
        public String fzManagerName;
        public String fzManagerno;



    	public DetailBean(RightsConfirmationList__c rcl ){
    		mainId = rcl.RightsConfirmation__c;
    		detailId = rcl.Id;

    		accName = rcl.AccountName__c;
    		accType = rcl.Account__r.DirectSale__c ;

            accpk = rcl.AccountPK__c;
            terminalpk = rcl.TerminalPK__c;

    		terminalLevel = rcl.TerminalAccount__r.Level__c;

    		province = rcl.Province__c;

    		terminalName = rcl.TerminalAccountName__c;
    		company = rcl.Company__c;
    		//cate = rcl.ProductTpye__c;

    		salerId = rcl.DirectBusinessOwner__c;
    		salerName = rcl.DirectBusinessOwner__r.Name;
            salerno = rcl.DirectBusinessOwner__r.ExuserCode__c;

    		salerManagerId = rcl.DirectBusinessOwnerManager__c;
    		salerManagerName = rcl.DirectBusinessOwnerManager__r.Name;
            salerMno = rcl.DirectBusinessOwnerManager__r.ExuserCode__c;

    		caterId = rcl.DistributionOwner__c;
    		caterName = rcl.DistributionOwner__r.Name;
            caterno = rcl.DistributionOwner__r.ExuserCode__c;

    		caterManagerId = rcl.DistributionOwnerManager__c;
    		caterManagerName = rcl.DistributionOwnerManager__r.Name;
            caterMno = rcl.DistributionOwnerManager__r.ExuserCode__c;

            provinceId = rcl.ProvinceManager__c;
            provinceName = rcl.ProvinceManager__r.Name;
            provinceno = rcl.ProvinceManager__r.ExuserCode__c;

    		thirdId = rcl.TripartiteOwner__c;
    		thirdName = rcl.TripartiteOwner__r.Name;
            thirdno = rcl.TripartiteOwner__r.ExuserCode__c;

    		thirdManagerId = rcl.TripartiteOwnerManager__c;
    		thirdManagerName = rcl.TripartiteOwnerManager__r.Name;
            thirdMno = rcl.TripartiteOwnerManager__r.ExuserCode__c;

            shId = rcl.BiochemicalIOwner__c;
            shName = rcl.BiochemicalIOwner__r.Name;
            shno = rcl.BiochemicalIOwner__r.ExuserCode__c;

            shManagerId = rcl.BiochemicalIOwnerManager__c;
            shManagerName = rcl.BiochemicalIOwnerManager__r.Name;
            shManagerno = rcl.BiochemicalIOwnerManager__r.ExuserCode__c;

            myId = rcl.ImmunityOwner__c;
            myName = rcl.ImmunityOwner__r.Name;
            myno = rcl.ImmunityOwner__r.ExuserCode__c;

            myManagerId = rcl.ImmunityOwnerManager__c;
            myManagerName = rcl.ImmunityOwnerManager__r.Name;
            myManagerno = rcl.ImmunityOwnerManager__r.ExuserCode__c;

            ljId = rcl.ClinicalLaboratoryOwner__c;
            ljName = rcl.ClinicalLaboratoryOwner__r.Name;
            ljno = rcl.ClinicalLaboratoryOwner__r.ExuserCode__c;

            ljManagerId = rcl.ClinicalLaboratoryOwnerManager__c;
            ljManagerName = rcl.ClinicalLaboratoryOwnerManager__r.Name;
            ljManagerno = rcl.ClinicalLaboratoryOwnerManager__r.ExuserCode__c;

            blId = rcl.PathologyOwner__c;
            blName = rcl.PathologyOwner__r.Name;
            blno = rcl.PathologyOwner__r.ExuserCode__c;

            blManagerId = rcl.PathologyOwnerManager__c;
            blManagerName = rcl.PathologyOwnerManager__r.Name;
            blManagerno = rcl.PathologyOwnerManager__r.ExuserCode__c;

            poctId = rcl.POCTOwner__c;
            poctName = rcl.POCTOwner__r.Name;
            poctno = rcl.POCTOwner__r.ExuserCode__c;

            poctManagerId = rcl.POCTOwnerManager__c;
            poctManagerName = rcl.POCTOwnerManager__r.Name;
            poctManagerno = rcl.POCTOwnerManager__r.ExuserCode__c;


            xsmkId = rcl.SysmexOwner__c;
            xsmkName = rcl.SysmexOwner__r.Name;
            xsmkno = rcl.SysmexOwner__r.ExuserCode__c;

            xsmkManagerId = rcl.SysmexOwnerManager__c;
            xsmkManagerName = rcl.SysmexOwnerManager__r.Name;
            xsmkManagerno = rcl.SysmexOwnerManager__r.ExuserCode__c;

            wswId = rcl.MicrobeOwner__c;
            wswName = rcl.MicrobeOwner__r.Name;
            wswno = rcl.MicrobeOwner__r.ExuserCode__c;

            wswManagerId = rcl.MicrobeOwnerManager__c;
            wswManagerName = rcl.MicrobeOwnerManager__r.Name;
            wswManagerno = rcl.MicrobeOwnerManager__r.ExuserCode__c;

            bdId = rcl.BDOwner__c;
            bdno = rcl.BDOwner__r.ExuserCode__c;
            bdName = rcl.BDOwner__r.Name;

            bdManagerId = rcl.BDOwnerManager__c;
            bdManagerName = rcl.BDOwnerManager__r.Name;
            bdManagerno = rcl.BDOwnerManager__r.ExuserCode__c;

            fzId = rcl.MolecularOwner__c;
            fzno = rcl.MolecularOwner__r.ExuserCode__c;
            fzName = rcl.MolecularOwner__r.Name;

            fzManagerId = rcl.MolecularOwnerManager__c;
            fzManagerName = rcl.MolecularOwnerManager__r.Name;
            fzManagerno = rcl.MolecularOwnerManager__r.ExuserCode__c;

    	}

    }


}